package day240415.work;

public class StudentTest {
    public static void main(String[] args) {
        //In OOP ,we create objects to solve complex problem;
        Student[] students=new Student[20];
        for (int i = 1; i <=20; i++) {
            Student student=new Student(i);
            students[i-1]=student;
        }
        System.out.println("学号"+students[0].number+"年级"+students[0].state+"成绩"+students[0].score);
        //问题1 只输出2年级的学生
        for (Student student : students)
            if (student.state == 2) {
                student.show();
            }
        //问题2 冒泡排序 根据学生成绩
        for (int i = 0; i < students.length-1 ; i++) {
            boolean swapped=false;
            for (int j = 0; j <(students.length-1)-i ; j++) {
                if (students[j].score>students[j+1].score){
                    Student temp=students[j];
                    students[j]=students[j+1];
                    students[j+1]=temp;
                    swapped=true;
                }
            }
            if (!swapped) break;
        }
        System.out.println("排序之后：");
        //谁来帮我解决一下
        //谁：已知自己写的或者别人写的
        //未知：自己创造（In OOP）
        for (Student student : students) {
            student.show();
        }
      }
    }


